import modal
from fastapi import FastAPI

app = modal.App("fastapi-app")
image = modal.Image.debian_slim().pip_install("fastapi")

web_app = FastAPI()

@web_app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

@web_app.post("/items/")
def create_item(item: dict):
    return {"message": "Item created", "item": item}

# 将 FastAPI 应用挂载到 Modal
@app.asgi_app(image=image)
def run_fastapi():
    return web_app